package com.ylr.demo3.AnnotationAndAOP;

import com.google.gson.JsonObject;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * @Author : JCccc
 * @CreateTime : 2020/3/27
 * @Description :
 **/
 
@Controller
@RequestMapping("/test")
@Slf4j
public class MyTestController {
 
    @ResponseBody
    @GetMapping("/testGet1")
    @LogAnnotation("testGet1 接口")
    public void testGet1(@RequestParam("userId") String userId, @RequestParam("toUserId") String toUserId) {
 
        System.out.println("已经进入GET测试接口,参数userId：" + userId+  "参数toUserId:"+toUserId);
    }
 
 
    @ResponseBody
    @GetMapping("/testGet2")
    @LogAnnotation("testGet2 接口")
    public void testGet2(@RequestParam Map map) {
 
        System.out.println("已经进入GET测试接口,参数：" + map.get("userId"));
    }
 
    @ResponseBody
    @PostMapping("/testPost1")
    @LogAnnotation("testPost1 接口")
    public void testPost1(@RequestBody Map map) {
 
        System.out.println("已经进入POST测试接口,参数：" + map.toString());
    }
 
    @ResponseBody
    @PostMapping("/testPost2")
    @LogAnnotation("testPost2 接口")
    public void testPost2(@RequestBody JsonObject jsonObject) {
 
        System.out.println("已经进入POST测试接口,参数：" + jsonObject.toString());
    }

    @GetMapping("/testGet3")
    @LogAnnotation("testGet3接口")
    public String testGet3(TestInf testInf){
        log.info("c层：");
        log.info(testInf.toString());
//        (testInf.toString());
        return "ok!";
    }


 
}


class TestInf extends TestBaseInf{
    @NotNull
    private int flied1;
    @NotNull
    private String flied2;
    private String flied3;
    private String flied4;
    private String flied5;

    public int getFlied1() {
        return flied1;
    }

    public void setFlied1(int flied1) {
        this.flied1 = flied1;
    }

    public String getFlied2() {
        return flied2;
    }

    public void setFlied2(String flied2) {
        this.flied2 = flied2;
    }

    public String getFlied3() {
        return flied3;
    }

    public void setFlied3(String flied3) {
        this.flied3 = flied3;
    }

    public String getFlied4() {
        return flied4;
    }

    public void setFlied4(String flied4) {
        this.flied4 = flied4;
    }

    public String getFlied5() {
        return flied5;
    }

    public void setFlied5(String flied5) {
        this.flied5 = flied5;
    }

    @Override
    public String toString() {
        return super.toString()+"\n" +"TestInf{" +
                "flied1=" + flied1 +
                ", flied2='" + flied2 + '\'' +
                ", flied3='" + flied3 + '\'' +
                ", flied4='" + flied4 + '\'' +
                ", flied5='" + flied5 + '\'' +
                '}';
    }
}

class TestBaseInf {
    @Min(groups = {TestValidate.class},value = 0)
    @Digits(groups = {TestValidate.class},fraction=0,integer=5)
    private int pageNo;
    @Min(groups = {TestValidate.class},value = 0)
    @Digits(groups = {TestValidate.class},fraction=0,integer=5)
    private int pageSize;
    private String order;

    public TestBaseInf() {
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    @Override
    public String toString() {
        return "TestBaseInf{" +
                "pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", order='" + order + '\'' +
                '}';
    }
}